﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Net;
using System.Net.Mail;
using Kojarskiy.Models;
using Mvc.Mailer;

namespace Kojarskiy.Core
{
    public class SmtpSettings
    {
        public string SmtpHost { get; set; }
        public int SmtpPort { get; set; }
        public bool UseDefaultCredentials { get; set; }
        public string SmtpUser { get; set; }
        public string SmtpPassword { get; set; }
        public bool EnableSsl { get; set; }
        public string AdminEmail { get; set; }

        public SmtpSettings()
        {
            var context = new KojarskiyDbEntities();
            List<Settings> settings = context.Settings.ToList();
            SmtpHost = settings.First(s => s.Name == "SmtpHost").Value;
            SmtpPort = Convert.ToInt32(settings.First(s => s.Name == "SmtpPort").Value);
            UseDefaultCredentials = Convert.ToBoolean(settings.First(s => s.Name == "UseDefaultCredentials").Value);
            SmtpUser = settings.First(s => s.Name == "SmtpUser").Value;
            SmtpPassword = settings.First(s => s.Name == "SmtpPassword").Value;
            EnableSsl = Convert.ToBoolean(settings.First(s => s.Name == "EnableSsl").Value);
            AdminEmail = settings.First(s => s.Name == "AdminEmail").Value;
        }
    }
}